Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Array give [object object] after pushing object inside

The array show as [object object] after I push the object inside it even though the object that are inside the array show up as what I want it to be . I tried searching google and YouTube but didn't find anything

let arr = []
let list = ""
let rev = {}
const btn = document.getElementById("savel")
btn.addEventListener("click", function() {
                 val1 = name.value
                 val2 = age.value
                shh ()                              
                console.log(val1)
})

function shh () {
     rev = {
                names: val1,
                ages: val2
}
showname.textContent = rev.names
showage.textContent = rev.ages
   arr.push(rev)
   console.log(arr)
   uul ()
}

function uul () {
                for (i=0; i<arr.length; i++) {
                                list = arr[i]
                }
                ul.innerHTML += `
                <li> ${list} </li>
                `
}
console.log(rev)
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You're appending to the list array after the for loop ends. Change the uul function to:

function uul () {
    for (i=0; i<arr.length; i++) {
        list = arr[I];
        ul.innerHTML += '<li> ${list} </li>';
    }           `
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You should use JSON.stringify().

If I have the following array and I try to show it in an alert

var myArray = [{name: "Jack"}, {name: "John"}];
alert(myArray);

The output will be [object Object],[object Object],

But if I use JSON.stringify:

alert(JSON.stringify(myArray))

the output will be [{"name":"Jack"},{"name":"John"}].

The same logic applies to your code and into the ul.innerHTML. Read more about here.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda